package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.dao.HotKeyDao;
import com.example.model.HotKeyModel;
import com.example.service.HotKeyService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 业务聚合
 *
 * @version [V2.0]
 * @package com.example.service.impl;
 * @description:[用一句话描述该文件做什么]
 * @author: [zhuben]
 * @date: [2024-02-02 12:59]
 * @copyright: 2024 echovin.com
 */
@Service
public class HotKeyServiceImpl extends ServiceImpl<HotKeyDao, HotKeyModel> implements HotKeyService {
    @Override
    public List<HotKeyModel> selectListByHotKey(String key, int current, int size) {
        if (StringUtils.isBlank(key)){
            return new ArrayList<>();
        }
        Page<HotKeyModel> page = new Page<>(current, size);
        LambdaQueryWrapper<HotKeyModel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HotKeyModel::getHotKey, key).orderByDesc(HotKeyModel::getScore);
        page = this.page(page, queryWrapper);
        return page.getRecords();
    }
}
